package de.fhhannover.inform.studienklassen.semester3;

import javax.swing.ImageIcon;

public class GeneralStatics {

	public static int[] twistArray(int[] in) {
		int[] tmp = new int[in.length];
		for (int i = 0, y = in.length - 1; i < in.length; i++, y--) {
			tmp[y] = in[i];
		}

		return tmp;
	}

	public static int[] connectArray(int[] inA, int[] inB) {
		int i = 0;
		int j = 0;
		// int y = 0;
		int x = 0;
		int[] tmp = new int[inA.length + inB.length];
		for (i = 0; i < inA.length; i++, j++) {
			tmp[j] = inA[i];
			/*
			 * if(noNulls &&tmp[j]==null) j--;
			 */
		}
		for (x = 0; x < inB.length; x++, j++) {
			tmp[j] = inB[x];
			/*
			 * if(noNulls && tmp[j]==0) j--;
			 */
		}
		/*
		 * if (noNulls){ int[] fin = new int[j]; for( i=0;i<fin.length;i++)
		 * fin[i]= tmp[i]; return fin;} else
		 */
		return tmp;
	}

	public static String intArrayToString(int[] in) {
		String s = "";
		s = intArrayToString(in, 11, true);
		return s;
	}

	public static String intArrayToSmartString(int[] in) {
		String s = "";
		s = intArrayToString(in, 11, false);
		return s;
	}

	public static String intArrayToString(int[] in, int linecount, boolean smart) {
		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < in.length; i++) {
			if (smart)
				sb.append("[" + i + "]=");
			sb.append(in[i]);
			sb.append("  ");
			if (i % linecount + 1 == 0 && i != 0)
				sb.append("\n");
		}
		String s = sb.toString();
		// System.out.println(s);
		return s;
	}

	public static int[] splitArray(int[] in, int a, int b) {
		int i = 0;
		int x = a;
		int[] tmp = new int[b - a + 1];
		for (x = a; x <= b; x++, i++) {
			tmp[i] = in[x];
		}
		return tmp;
	}

	public static int[] replaceInArray(int[] tmp, int[] in, int startindex,
			int endindex) {
		int i = 0;
		int x = startindex;

		for (x = startindex; x <= endindex; x++, i++) {
			tmp[x] = in[i];
		}

		return tmp;
	}

	static public ImageIcon createImageIcon(String path, String description,
			Object obj) {
		java.net.URL imgURL = obj.getClass().getResource(path);
		if (imgURL != null) {
			return new ImageIcon(imgURL, description);
		} else {
			System.err.println("Couldn't find file: " + path);
			return null;
		}
	}

}
